﻿
package system.base;

import framework.core.*;
import system.SelectManager;
import system.data.*;

/*
	Author    :Benny
	CreateTime:2008-05-15 14:22:28
*/
public class WarehouseProductView extends WarehouseProductViewBase 
{

//----system generated start----// 	
public WarehouseProductView() 
{
	
}

private static void delete(DBConnection con, String id) throws Exception
{
	Conditions conditions = new Conditions();
	conditions.add(ID, id);	
	delete(con,TABLE_NAME,conditions);
}
public static WarehouseProductView fetch()
{
	return new WarehouseProductView();
}
public static WarehouseProductView copy(WarehouseProductView srcObj)
{
	WarehouseProductView obj = fetch();
	obj.copyBase(srcObj);
	return obj;
}
public static WarehouseProductView fetch(DBConnection con, String id) throws Exception
{
	Conditions conditions = new Conditions();
	conditions.add(ID,id);
	
	return fetch(con,conditions);
}
public static WarehouseProductView fetch(DBConnection con,Conditions conditions) throws Exception
{
	DBResult result = null;
	try
	{
		result = DBEngine.doSelect(con,"select * from " + TABLE_NAME,conditions);
		java.sql.ResultSet rs = result.getRs();
		WarehouseProductView obj = null;
		if(rs.next())
		{
			obj = fetch(rs);
		}
		return obj;
	}
	finally
	{
		if(result!=null) result.clear() ;
	}
}
public static WarehouseProductView fetch(java.sql.ResultSet rs) throws Exception
{
	WarehouseProductView obj = new WarehouseProductView();
	obj.initObject(rs);
	return obj;
}
protected void getUnique(DBConnection con) throws Exception
{
		setId(DBEngine.getId(con));
}
//----system generated end----//



//----add by Wing start----//
public static boolean IsCheckedOfWarehouseCode(String loginWarehouseCode,String warehouseCode) throws Exception
{
    boolean checked = false;
    if(loginWarehouseCode != null) {
        if (loginWarehouseCode.equals(warehouseCode)) return true;
    }
    return checked;
}

public static int getDullStorageTimes(String lastUpdateTime) {
    int dullTimes = 0;
    DateUtil dateUtil1 = new DateUtil();
    dateUtil1.advanceDays(-60+1);
    String date1 = dateUtil1.getFullString();
    DateUtil dateUtil2 = new DateUtil();
    dateUtil2.advanceDays(-90+1);
    String date2 = dateUtil2.getFullString();
    DateUtil dateUtil3 = new DateUtil();
    dateUtil3.advanceDays(-180+1);
    String date3 = dateUtil3.getFullString();
    if (lastUpdateTime.compareTo(date3) <= 0) {
        dullTimes = 180;
    } else if (lastUpdateTime.compareTo(date2) <= 0) {
        dullTimes = 90;
    } else if (lastUpdateTime.compareTo(date1) <= 0) {
        dullTimes = 60;
    }
    return dullTimes;
}

//----add by Wing end----//

//add by Jackey start --//
public String viewWarehouseName(DBConnection con) throws Exception
{
    String mReturn = "";
    Warehouse w = Warehouse.fetchByCode(con, getWarehouseCode());  
    if (w != null)
    {
        mReturn = w.getName();
    }
    return  mReturn;
}

public String viewProductCount(DBConnection con) throws Exception
{
    return StringUtil.showCount(String.valueOf(getProductCount()));
}
// add by Jackey end

}

